<?php
/*
 *	Created on 2008-04-17 / 19:09:44
 *	Filename: handle_errors.php
 *	User: tomusdrw (tomusdrw.blacksoft.eu)
 *	@author: Blacksoft.eu (c) 2008
 *	@package: tempaq2
 *	
 */
 function MyErrorHandler($errno, $errstr, $errfile, $errline, $errcontext=null) {
 	$error="";
 	$errlvl = 0;
 	$err_module = ((isset($errcontext['bot']->exec_module))?$errcontext['bot']->exec_module:null);
 	$err_module = ((isset($errcontext['this']->exec_module))?$errcontext['this']->exec_module:null);
 	switch ($errno) {
 		case E_ERROR:
	    case E_USER_ERROR:
	    	$errlvl = 1;
	    	$errtype = DBG_ERROR;
	        $error = "ERROR: [$errno] $errstr";
	        $error .= "  Fatal error on line $errline in file $errfile";
	        //$error .= ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
	        if (file_exists(BOT_LOCK_FILE))
	        	unlink(BOT_LOCK_FILE);
	        exit(1);
	        break;
	    case E_WARNING:
	    case E_USER_WARNING:
	    	$errlvl = 2;
	    	$errtype = DBG_WARN;
	        $error = "WARNING: [$errno] $errstr";
	        $error .= "   in $errfile:$errline";
	        break;
	    case E_NOTICE:
	    case E_USER_NOTICE:
	    	$errlvl = 2;
	    	$errtype = DBG_INFO;
	        $error = "NOTICE: [$errno] $errstr";
	        $error .= "   in $errfile:$errline";
	        break;
	    default:
	    	$errlvl = 2;
	    	$errtype = DBG_OTHER;
	        $error = "Unknown error type: [$errno] $errstr";
	        $error .= "   in $errfile:$errline";
	        break;
    }
    $error .= ((!empty($err_module))?' Module: '.$err_module:null)."\n";
    debug($error, $errtype, $errlvl);

    /* Don't execute PHP internal error handler */
    return true;
 }

 $old_error_handler = set_error_handler("myErrorHandler");
 
?>